package com.atguigu.flink.chapter5.transform;

import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink02_Transform_Map_Rich {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
        DataStreamSource<Integer> source = env.fromElements(1, 10, 20, 30, 100);
        source
          .map(new RichMapFunction<Integer, Integer>() {
              @Override
              public void open(Configuration parameters) throws Exception {
                  System.out.println("open 执行一次");
              }

              @Override
              public Integer map(Integer value) throws Exception {
                  System.out.println("map 每个元素执行一次");
                  return value * value;
              }

              @Override
              public void close() throws Exception {
                  System.out.println("close 执行一次");
              }
          })
          .print();


        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
